import React, {useEffect, useState, useCallback, useMemo} from 'react';

import {Text, View, BackHandler, Platform} from 'react-native';
import Step from './step';
import Popup from './step/popup';
const App = () => {
  const [arr, setisPlay] = useState([1, 0, 1, 0, 0, 0, 0]);
  const [checkIn, setCheckIn] = useState(0);

  //最后一次签到日期
  const lastCheckIn = useMemo(() => {
    let count = -1;
    if (checkIn === 1) {
      arr.forEach((element, index) => {
        if (element > 0) {
          count = index;
        }
      });
    }
    return count;
  }, [arr, checkIn]);

  useEffect(() => {
    if (Platform.OS === 'android') {
      BackHandler.addEventListener('hardwareBackPress', () => {
        console.log(2312);
        return true;
      });
    }
    // setTimeout(() => {
    //   setisPlay([1, 0, 1, 1, 0, 0, 0]);
    //   setCheckIn(1);
    // }, 4000);
  }, []);

  // 运动完成之后的回调函数， 执行签到进度条的事件
  const callBack = useCallback(() => {
    console.log(2321);
  }, []);
  return (
    <View>
      <Text>23432</Text>
      <Popup close={() => {}} show={false} />
      <Step
        checkInCount={2}
        arr={arr}
        checkIn={checkIn}
        callBack={callBack}
        lastCheckIn={lastCheckIn}
      />
    </View>
  );
};

export default App;
